<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <link type="text/css" rel="stylesheet" media="all" href="../styles/global.css"/>
    <link type="text/css" rel="stylesheet" media="all" href="../styles/global_color.css"/>
    <script src="../js/jquery-3.2.1.js"></script>
    <script language="javascript" type="text/javascript">
        $.ajax({
            url: "/selectAllModules",
            type: "post",
            success: function (result) {
                console.log(result)

                if (result.indexOf("角色管理") == -1) {
                    document.getElementById("lia1").style.display = "none"
                }
                if (result.indexOf("管理员管理") == -1) {
                    document.getElementById("lia2").style.display = "none"
                }
                if (result.indexOf("资费管理") == -1) {
                    document.getElementById("lia3").style.display = "none"
                }
                if (result.indexOf("账务账号管理") == -1) {
                    document.getElementById("lia4").style.display = "none"
                }
                if (result.indexOf("业务账号管理") ==-1) {
                    document.getElementById("lia5").style.display = "none"
                }
                if (result.indexOf("账单管理") ==-1) {
                    document.getElementById("lia6").style.display = "none"
                }
                if (result.indexOf("报表管理") == -1) {
                    document.getElementById("lia7").style.display = "none"
                }
            }
        });


        //显示角色详细信息
        function showDetail(flag, a) {
            var detailDiv = a.parentNode.getElementsByTagName("div")[0];
            if (flag) {
                detailDiv.style.display = "block";
            }
            else
                detailDiv.style.display = "none";
        }

        //下拉选权限列表
        $.ajax({
            url: "allrole",
            type: "post",
            success: function (result) {
                var roleList = result.data;
                for (var i in roleList) {
                    var role = roleList[i]
                    $("#selModules").append(" <option>" + role.name + "</option>")
                }
            }
        })


//        $.ajax({
//            url: "alladmin",
//            type: "post",
//            success: function (result) {
//                var code = result.Code
//                if (code == 0) {
//                    alert(result.message)
//                }
//                var adminList = result.data;
//                for (var i in adminList) {
//                    var admin = adminList[i];
//                    addNewTR(admin);
//                }
//            }
//        })


        $.ajax({
            url: "adminpage",
            type: "type",
            success: function (result) {
                var roleList = result.list;
                var pages = result.pages;
                var pageNum = result.pageNum;
                var isFirstPage = result.isFirstPage;
                var isLastPage = result.isLastPage;
                for (var i in roleList) {
                    var role = roleList[i];
                    addNewTR(role);
                }
                $("#pages").append("<a id='up'>上一页</a>")

                for (var i = 1; i < pages+1; i++) {
                    if (i == pageNum) {
                        $("#pages").append("<a id=" + i + "; class='current_page'; onclick='changePage(" + i + ")'>" + i + "</a>")
                    } else {
                        $("#pages").append("<a id=" + i + "; onclick='changePage(" + i + ")'>" + i + "</a>")
                    }
                }
                $("#pages").append("<a id='down'>下一页</a>")
                if (!isFirstPage) {
                    var num = pageNum - 1;
                    $("#up").attr("onclick", "changePage(" + num + ")");
                }
                if (!isLastPage) {
                    var num = pageNum + 1;
                    $("#down").attr("onclick", "changePage(" + num + ")");
                }
            }
        })

        function changePage(pagenum) {

            $.ajax({
                url: "adminpage",
                type: "post",
                data: {
                    pagenum: pagenum,
                },
                success: function (result) {
                    $("#adminlist").empty();
                    $("#pages").empty();
                    var roleList = result.list;
                    var pages = result.pages;
                    var pageNum = result.pageNum;
                    var isFirstPage = result.isFirstPage;
                    var isLastPage = result.isLastPage;
                    for (var i in roleList) {
                        var role = roleList[i];
                        addNewTR(role);
                    }
                    $("#pages").append("<a id='up'>上一页</a>")
                    if (!isFirstPage) {
                        var num = pageNum - 1;
                        $("#up").attr("onclick", "changePage(" + num + ")");
                    }
                    for (var i = 1; i < pages+1; i++) {
                        if (i == pageNum) {
                            $("#pages").append("<a id=" + i + "; class='current_page'; onclick='changePage(" + i + ")'>" + i + "</a>")
                        } else {
                            $("#pages").append("<a id=" + i + "; onclick='changePage(" + i + ")'>" + i + "</a>")
                        }
                    }
                    $("#pages").append("<a id='down'>下一页</a>")
                    if (!isLastPage) {
                        var num = pageNum + 1;
                        $("#down").attr("onclick", "changePage(" + num + ")");
                    }
                }
            })
        }


        function addNewTR(admin) {
            var roleList = admin.roleList;
            var desc = "";
            var content = "";
            for (var i in roleList) {
                var role = roleList[i];
                var roledesc = roleList[i];
                var rolename = role.name + ",";
                desc = roledesc.name;
                content += rolename;
            }

            $("#adminlist").append($("<tr><td><input type=checkbox name='admin' value='" + admin.adminId + "'/></td><td>" + admin.adminId + "</td><td>" + admin.name + "</td><td>" + admin.adminCode + "</td><td>" + admin.telephone + "</td><td>" + admin.email + "</td><td>" + admin.enrolldate + "</td>" +
                    "<td><a class=summary  onmouseover=showDetail(true,this); onmouseout=showDetail(false,this);>" + desc+"..." + "</a>" +
                    <!--浮动的详细信息-->
                    "<div class=detail_info>" + content + "</div></td>" +
                    "<td>" +
                    "<input type=button value=修改 class=btn_modify onclick=location.href='adminupdate?adminId=" + admin.adminId + "'; />" +
                    "<input type=button value=删除 class=btn_delete onclick=deleteAdmin(" + admin.adminId + "); />" +
                    "</td></tr>"));
        }


        function closeClick(isclose) {
            if (isclose){
                $("#search").attr("onclick","");
            }else {
                $("#search").attr("onclick","searchclick()");
            }
        }

        function searchclick() {
            closeClick(true);
            var name = "";
            if ($("#name").val() != null) {
                name = $("#name").val()
            }
            $("#adminlist").empty();
            $.ajax({
                url: "searchadmin",
                type: "post",
                data: {
                    roleName: $("#selModules").val(),
                    name: name
                },
                success: function (result) {
                    var code = result.Code;
                    if (code == 0) {
                        alert(result.message)
                    }
                    var adminList = result.data;
                    for (var i in adminList) {
                        var admin = adminList[i];
                        addNewTR(admin);
                    }
                }
            });
            window.setTimeout("closeClick(false);", 1000);
        }


        //重置密码
        function resetPwd() {
            var admins = new Array();
            $("input[name=admin]").each(function (i, d) {
                if (d.checked) {
                    admins.push(d.value);
                }
            })
            if (admins.length < 1) {
                alert("您没有选中项!");
            }
            $.ajax({
                url: "resetpwd",
                type: "post",
                data: {
                    admin: admins
                },
                success: function (result) {
                    alert(result.message)
                }
            })
        }
        //删除
        function deleteAdmin(id) {
            var r = window.confirm("确定要删除此角色吗？");
            if (r == true) {
                $.ajax({
                    url: "deladmin?adminId=" + id,
                    type: "post",
                    success: function (result) {
                        alert(result.message)
                        window.location.href = "adminlist";
                    }
                })

            }
        }
        //全选
        function selectAdmins(inputObj) {
            var inputArray = document.getElementById("datalist").getElementsByTagName("input");
            for (var i = 1; i < inputArray.length; i++) {
                if (inputArray[i].type == "checkbox") {
                    inputArray[i].checked = inputObj.checked;
                }
            }
        }
    </script>
</head>
<body>
<!--Logo区域开始-->
<div id="header">
    <img src="../images/logo.png" alt="logo" class="left"/>
    <a href="/logout">[退出]</a>
</div>
<!--Logo区域结束-->
<!--导航区域开始-->
<div id="navi">
    <ul id="menu">
        <li><a href="../index.html" class="index_off"></a></li>
        <li id="lia1"><a href="rolelist" class="role_off"></a></li>
        <li id="lia2"><a href="adminlist" class="admin_on"></a></li>
        <li id="lia3"><a href="fee" class="fee_off"></a></li>
        <li id="lia4"><a href="accountlist" class="account_off"></a></li>
        <li id="lia5"><a href="servicelist" class="service_off"></a></li>
        <li id="lia6"><a href="bill" class="bill_off"></a></li>
        <li id="lia7"><a href="report" class="report_off"></a></li>
        <li><a href="userinfo" class="information_off"></a></li>
        <li><a href="changepsw" class="password_off"></a></li>
    </ul>
</div>
<!--导航区域结束-->
<!--主要区域开始-->
<div id="main">
    <form action="" method="">
        <!--查询-->
        <div class="search_add">
            <div>
                按角色：
                <select id="selModules" class="select_search">
                    <option>全部</option>
                </select>
            </div>
            <div>管理员姓名：<input type="text" value="" class="text_search width200" name="name" id="name"/></div>
            <div><input type="button" value="搜索" class="btn_search" id="search" onclick="searchclick()" /></div>
            <input type="button" value="密码重置" class="btn_add" onclick="resetPwd();"/>
            <input type="button" value="增加" class="btn_add" onclick="location.href='adminadd';"/>
        </div>
        <!--删除和密码重置的操作提示-->
        <div id="operate_result_info" class="operate_fail">
            <img src="../images/close.png" onclick="this.parentNode.style.display='none';"/>
            <span>删除失败！数据并发错误。</span><!--密码重置失败！数据并发错误。-->
        </div>
        <!--数据区域：用表格展示数据-->
        <div id="data">
            <table id="datalist">
                <tr>
                    <th class="th_select_all">
                        <input type="checkbox" onclick="selectAdmins(this);"/>
                        <span>全选</span>
                    </th>
                    <th>管理员ID</th>
                    <th>姓名</th>
                    <th>登录名</th>
                    <th>电话</th>
                    <th>电子邮件</th>
                    <th>授权日期</th>
                    <th class="width100">拥有角色</th>
                    <th></th>
                </tr>
                <tbody id="adminlist">

                </tbody>


            </table>
        </div>
        <!--分页-->
        <div id="pages">

        </div>
    </form>
</div>
<!--主要区域结束-->
<div id="footer">
    <p>[源自北美的技术，最优秀的师资，最真实的企业环境，最适用的实战项目]</p>
    <span>版权所有(C)云科技有限公司 </span>
</div>
</body>
</html>
